<template>
    <card>
        <Row class="btns">
            <Col offset="18">
                <Button type="success" @click="productSumbit" :loading="submitLoading">提交</Button>
                <Button @click="backPage" type="success">返回</Button>
            </Col>
        </Row>
        <Tabs type="card" :animated="false">
            <TabPane label="审批信息" name="proposal">
                <countersignApprovalInfo :planId="parms.planId" :stageId="parms.stageId" :isBack="isBack" ref="child"/>
            </TabPane>
            <TabPane label="产品方案详情" name="name2">
                <productLaunchTabOne :planId="parms.planId"/>
            </TabPane>
            <TabPane label="附件上传" name="name3">
                <productLaunchTabTwo :planId="parms.planId"/>
            </TabPane>
        </Tabs>

    </card>
</template>
<script>
    import countersignApprovalInfo from "./countersignApprovalInfo.vue";
    import productLaunchTabOne from "./productLaunchTabOne.vue";
    import productLaunchTabTwo from "../common/common-attachment.vue";
    import {
        getProposalApplicationInfo,
        saveProposalApplicationInfo
    } from "@/projects/afs-core-business/api/afs-product/product-launch/productLaunch";

    export default {
        name: "countersign-approval",
        props: {
            parms: {
                Object
            }
        },
        data() {
            return {
                submitLoading: false,
                isBack:true,
            }
        },
        components: {
            countersignApprovalInfo,
            productLaunchTabOne,
            productLaunchTabTwo,
        },
        methods: {
            backPage() {
                this.$emit("backPage", "返回");
            },
            productSumbit() {
                let result = this.$refs['child'].validateForm();
                if (result.flag) {
                    this.submitLoading = true;
                    // console.info("提交结果："+JSON.stringify(result.productImplemente));
                    let productImplemente = result.productImplemente;
                    productImplemente["isUpdate"] = false;
                    productImplemente["isFinalJudgment"] = false;
                    productImplemente["id"] = this.parms.planId;
                    if ('sales' == this.parms.taskNodeId ) {
                        productImplemente["isUpdate"] = true;
                    }
                    if ('accounte' == this.parms.taskNodeId ) { //终审
                        productImplemente["isFinalJudgment"] = true;
                    }
                    saveProposalApplicationInfo(productImplemente).then(res => {
                        this.submitLoading = false;
                        if (res.code === "0000") {
                            this.backPage();
                        }
                        this.$Message.success(res.msg);
                    }).catch(() => {
                        this.submitLoading = false;
                    });
                }
            },
        },
        mounted() {
            if ('sales' == this.parms.taskNodeId ) {
                this.isBack = false;
            }
        },
    };
</script>
